<style type="text/css">
</style>
<template>
    <i-form ref="formValidate" :model="formValidate" :rules="ruleValidate" :label-width="110">
        <Form-item label="门区名称" prop="Gatename">
            <i-input v-model="formValidate.Gatename" placeholder="请输入门区名称"></i-input>
        </Form-item>
        <Form-item label="门区描述或门区控制区域描述" prop="Comment">
            <i-input v-model="formValidate.Comment" placeholder="请输入门区描述或门区控制区域描述"></i-input>
        </Form-item>
        <Form-item label="远端客户端IP" prop="Remoteip">
            <i-input v-model="formValidate.Remoteip" placeholder="请输入远端客户端IP"></i-input>
        </Form-item>
        <Form-item label="门区通行开始时间">
            <Row>
                <i-col span="11">
                    <Time-picker :value="starttime" format="HH:mm:ss" @on-change="changeStartDate2"
                                 type="time"
                                 placement="bottom-end"
                                 placeholder="选择时间" width="280px"></Time-picker>
                </i-col>
            </Row>
        </Form-item>
        <Form-item label="门区通行结束时间">
            <Row>
                <i-col span="11">
                    <Time-picker :value="endtime" format="HH:mm:ss" @on-change="changeEndDate2"
                                 type="time"
                                 placement="bottom-end"
                                 placeholder="选择时间" width="280px">
                    </Time-picker>
                </i-col>
            </Row>
        </Form-item>
        <Form-item label="区域" prop="Areaid">
            <i-select v-model="formValidate.Areaid" placeholder="请选择区域">
                <template v-for="(item,index) in areaArr">
                    <i-option :value="item.Id">{{item.Title}}</i-option>
                </template>
            </i-select>
        </Form-item>
        <Form-item>
            <i-button @click="handleSubmit('formValidate')" type="primary">提交</i-button>
            <i-button type="ghost" @click="jumpPage('','GateServerList')" style="margin-left: 8px">返回</i-button>
        </Form-item>
    </i-form>
</template>
<script>
    import apiUtil from '../../assets/utils/api_util';
    import baseUtil from '../../assets/utils/base-util';

    export default {
        data() {
            return {
                formValidate: {
                    //添加字段
                    Gatename: '',
                    Comment: '',
                    Areaid: '',
                    Remoteip: '',
                    starttime:'',
                    endtime:'',
                },
                ruleValidate: {
                },
                areaArr:[],
            }
        },
        mounted: function () {
            this.getAreaData();
        },

        methods: {
            //跳转
            jumpPage: function (id, url) {
                //跳转
                let route = '';
                if (id.length > 0) {
                    route = {
                        path: url,
                        query: {
                            id: id
                        },
                    };
                } else {
                    route = {
                        path: url,
                    };
                }

                this.$router.push(route);
            },
            getAreaData() {
                let that = this;

                let para = {
                };
                let params = that.$qs.stringify(para);

                this.$Loading.start();

                apiUtil.get(that, apiUtil.urls.GetAreas, para, function (res) {
                    that.$Loading.finish();
                    that.areaArr = res.Msg;
                });

            },
            changeStartDate2: function (date) {
                console.log(date);
                this.formValidate.starttime = date;
                console.log('starttime:',this.formValidate.starttime);

            },
            changeEndDate2: function (date) {
                console.log(date);
                this.formValidate.endtime = date;
            },
            //添加
            handleSubmit(name) {

                let that = this;
                let model = this.$refs[name].model;
                this.$refs[name].validate((valid) => {
                    that.addData(model);
                })
            },
            addData: function (model) {
                let that = this;

                let params = that.$qs.stringify(model);
                this.$Loading.start();

                apiUtil.post(that,apiUtil.urls.AddGateServer, params, function (res) {
                    that.$Loading.finish();

                    that.$Modal.confirm({
                        title: '操作成功',
                        content: '请选择下一步操作',
                        okText: '继续添加',
                        cancelText: '返回列表',
                        onOk: () => {
                            // baseUtil.pageJump(that,'','GateServerAdd')
                        },
                        onCancel: () => {
                            baseUtil.pageJump(that,'','GateServerList')

                        }
                    });
                });
            },

            uploadList() {
                let that = this;
                this.imageList = that.$refs.upload ? that.$refs.upload.fileList : [];
                console.log('this.imageList:', this.imageList);
                // return ;
            },

        }
    }
</script>
